package com.zfei.gfb.request;

import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.lang.Validator;
import com.zfei.gfb.bean.Const;
import com.zfei.gfb.bean.Status;
import com.zfei.gfb.bean.StatusException;
import com.zfei.gfb.util.Gsons;
import com.zfei.gfb.util.ObjUtil;
import io.swagger.annotations.ApiModelProperty;
import org.apache.commons.lang3.StringUtils;

import java.util.List;


/**
 * @author fgh
 */
public class GfbHouseAuditRequest {

    @ApiModelProperty(value = "房子id", required = true)
    private Integer id;
    @ApiModelProperty(value = "审核状态，通过1，不通过2", required = true)
    private Integer status;
    @ApiModelProperty(value = "不通过原因", required = false)
    private String reason;
    @ApiModelProperty(value = "消防图片,数组", required = true)
    private List<String> checkImages;


    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    public Integer getStatus() {
        return status;
    }

    public void setStatus(Integer status) {
        this.status = status;
    }

    public String getReason() {
        return reason;
    }

    public void setReason(String reason) {
        this.reason = reason;
    }

    public List<String> getCheckImages() {
        return checkImages;
    }

    public void setCheckImages(List<String> checkImages) {
        this.checkImages = checkImages;
    }

    public void checkUpdateNull() {
        if (ObjUtil.anyNull(id, status)) {
            throw new StatusException(Status.INVALID_ARGUMENT);
        }
        if (CollectionUtil.isEmpty(checkImages)) {
            throw new StatusException(Status.INVALID_ARGUMENT);
        } else {
            for (String checkImage : checkImages) {
                if (!Validator.isUrl(checkImage)) {
                    throw new StatusException(Status.INVALID_ARGUMENT);
                }
            }
        }
        if (status != Const.HOUSE_STATUS_OFF && status != Const.HOUSE_STATUS_ON) {
            throw new StatusException(Status.INVALID_ARGUMENT);
        }
        if (status == Const.HOUSE_STATUS_OFF) {
            if (StringUtils.isBlank(reason)) {
                throw new StatusException(Status.INVALID_ARGUMENT);
            }
            if(reason.length() > Const.CONTENT_LENGTH){
                throw new StatusException(Status.INVALID_ARGUMENT);
            }
        }
    }
}

